import { Warning, Link } from '@brillout/docpress'

You can programmatically trigger <Link href="/pre-rendering">pre-rendering</Link>:

```js
// my-build-script.js

import { prerender } from 'vike/prerender'

// Without options
prerender()

// All options are optional
prerender({
  pageContextInit,
  viteConfig,
  onPagePrerender
})
```

> Use <Link href="/prerender#disableautorun" /> to avoid pre-rendering to be run twice.


## `pageContextInit`

The initial value of each page's `pageContext` object.

```js
prerender({
  pageContextInit: {
    someData: 42,
    // ...
  }
})
```

## `viteConfig`

The Vite config.

It's optional: if omitted, Vite automatically loads `vite.config.js`.

We recommend to either omit this option or set it to `prerender({ viteConfig: { root }})`: the `vite.config.js` file living at `root` will be loaded.

Alternatively you can:
 - Set:
   ```js
   prerender({
     viteConfig: {
       configFile: require.resolve('./path/to/vite.config.js')
     }
   })
   ```
 - Not load any `vite.config.js` file and, instead, use `prerender({ viteConfig: { configFile: false, ...myViteConfig }})` to programmatically define the entire Vite config.

You can also load a `vite.config.js` file while overriding parts of the Vite config.

See [Vite > JavaScript API > `InlineConfig`](https://vitejs.dev/guide/api-javascript.html#inlineconfig).


## `onPagePrerender()`

<Warning>Don't use this option without having contacted a Vike maintainer: this functionality may be changed/removed at any time if you don't.</Warning>

The `onPagePrerender` option allows you to control where/how HTML files are written.

```js
prerender({
  // If onPagePrerender() is set, then Vike won't write the HTML files to the filesystem
  onPagePrerender(pageContext) {
    // Write the HTML to the filesystem
    // ...
  }
})
```


## More settings

For more settings, see <Link href="/prerender" />.


## See also

- <Link href="/command-prerender" />
- <Link href="/prerender#disableautorun" />
- <Link href="/pre-rendering" />
